package com.mr.cai.main.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cai.mr.lib.utils.LogInfo;
import com.mr.cai.main.R;
import com.mr.cai.main.bean.GroupInfoBean;
import com.mr.cai.main.utils.CommonCoreUtil;

/**
 * Created by hai8108 on 16/2/11.
 */
public class GroupFragmentAdapter extends MrCaiBaseAdapter {
    private int columNum=2;
    private int screentWidth;
    private int itemWidth;
    public GroupFragmentAdapter (Activity context) {
        super(context);
        screentWidth= CommonCoreUtil.getScreenWidth();
        int offset = (int)mContext.getResources().getDimension(R.dimen.dimen_5);
        itemWidth = (screentWidth-((columNum+1)*offset)) /columNum;
    }
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        LogInfo.log("haitian", "position ="+position);
        if(getList() == null || getList().size() <=0){
            return null;
        }
        GroupInfoBean groupInfoBean = (GroupInfoBean) getItem(position);
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView= View.inflate(mContext, R.layout.fragment_group_page_item_layout,null);
            RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams
                    (RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
            imageParams.width=itemWidth;
            imageParams.height=itemWidth;
            viewHolder.groupIv = (ImageView) convertView.findViewById(R.id.group_iv);
            viewHolder.groupIv.setLayoutParams(imageParams);
            viewHolder.groupEngName = (TextView) convertView.findViewById(R.id.group_english_name);
            viewHolder.groupChinaName = (TextView) convertView.findViewById(R.id.group_chinese_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.groupChinaName.setText(groupInfoBean.getgChinaName());
        viewHolder.groupEngName.setText(groupInfoBean.getgEngName());
        return convertView;
    }
    public static  class ViewHolder{
        private ImageView groupIv;
        private TextView groupEngName;
        private TextView groupChinaName;
    }
}
